/**
 * 
 */
package com.thor.palmmall.rest.chart.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.chart.ASalesStore;
import com.thor.palmmall.spi.chart.SSalesStore;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class ASalesStoreConverter implements Converter<SSalesStore, ASalesStore> {

  public static ASalesStoreConverter getInstance() {
    if (instance == null)
      instance = new ASalesStoreConverter();
    return instance;
  }

  private static ASalesStoreConverter instance;

  private ASalesStoreConverter() {
  }

  @Override
  public ASalesStore convert(SSalesStore source) {
    if (source == null) {
      return null;
    }
    ASalesStore target = new ASalesStore();
    target.setCompLastCalcRate(source.getCompLastCalcRate());
    target.setSalePerArea(source.getSalePerArea());
    target.setSales(source.getSales());
    target.setSalesPerDay(source.getSalesPerDay());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setDetails(
        ConverterUtil.convert(source.getDetails(), AStoreDetailsConverter.getInstance()));
    return target;
  }

}
